package com.desktop.click.tool.util;

import com.desktop.click.tool.entity.RobotClickProperties;

import java.awt.*;
import java.awt.event.InputEvent;
import java.io.Serializable;
import java.util.List;

public class RobotUtil  {

    private static volatile boolean runStatus = false;
//    private static Robot robot;

//    static {
//        try {
//            robot = new Robot();
//        } catch (AWTException e) {
//            e.printStackTrace();
//        }
//    }

    public static void robotRun(List<RobotClickProperties> properties) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                runStatus = true;
                while (runStatus) {
                    for (RobotClickProperties item : properties) {
                        Robot robot = null;
                        try {
                            robot = new Robot();
                        } catch (AWTException e) {
                            e.printStackTrace();
                        }
                        robot.mouseMove(-1, -1);
                        robot.mouseMove(item.getX(), item.getY());

                        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);

                        robot.delay(100);

                        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

                        robot.delay(item.getDelay());
                    }

                }

            }
        }).start();

    }

    public static void stop() {
        runStatus = false;
    }

    public static boolean getRunStatus() {
        return runStatus;
    }
}
